package com.motorola.dp.jenkinsmonitor.service.util.svn;

import java.util.List;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import com.motorola.dp.jenkinsmonitor.model.util.HttpRequestParameters;
import com.motorola.dp.jenkinsmonitor.model.util.svn.SvnFoldersList;
import com.motorola.dp.jenkinsmonitor.service.util.xml.RemoteXmlParsingService;

@Service("svnService")
public class DefaultSvnService implements SvnService {

    @Value("#{remoteXmlParsingService}")
    private RemoteXmlParsingService remoteXmlParsingService;

    @Value("#{svnServiceHelper}")
    private SvnServiceHelper svnServiceHelper;

    public List<String> getFolderNames(String path) {
        HttpRequestParameters foldersRequest = svnServiceHelper.createSvnResourceRequest(path);
        SvnFoldersList folders = remoteXmlParsingService.parseRemoteXml(foldersRequest, SvnFoldersList.class);
        List<String> folderNames = folders.getFolderNames();
        return folderNames;
    }

    public <T> T parseRemoteSvnXml(String module, String resource, Class<T> resourceClass) {
        HttpRequestParameters resourceRequest = svnServiceHelper.createSvnResourceRequest(module, resource);
        T parsedResource = remoteXmlParsingService.parseRemoteXml(resourceRequest, resourceClass);
        return parsedResource;
    }

    public void setRemoteXmlParsingService(RemoteXmlParsingService remoteXmlParsingService) {
        this.remoteXmlParsingService = remoteXmlParsingService;
    }

    public void setSvnServiceHelper(SvnServiceHelper svnServiceHelper) {
        this.svnServiceHelper = svnServiceHelper;
    }
}
